import 'package:open_file/open_file.dart';

export 'package:open_file/open_file.dart';
/**
 * @Description: 打开文件
 * @Author: 下雨了
 * @CreateDate: 2021-12-17 13:25
 * @UpdateUser: 更新者
 * @UpdateDate:  2021-12-17 13:25
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
///
//
// dependencies:
//    # 打开文件
//    open_file: ^3.2.1
//    #文件选择器
//    file_picker: ^4.3.0
//

class OpenFileUtils {
  // 私有构造函数
  OpenFileUtils._internal();

  // 保存单例
  static final OpenFileUtils _openFileUtils = OpenFileUtils._internal();

  // 工厂构造函数
  factory OpenFileUtils() => _openFileUtils;

  /// 打开文件
  Future<OpenResult> open(String filePath,
      {String? type,
      String? uti,
      String linuxDesktopName = "xdg",
      bool linuxByProcess = false}) async {
    // 文件选择器
    // FilePickerResult? result = await FilePicker.platform.pickFiles();
    //
    // if (result != null) {
    //   filePath = result.files.single.path.toString();
    // } else {}

    final _result = await OpenFile.open(filePath,
        type: type,
        uti: uti,
        linuxDesktopName: linuxDesktopName,
        linuxByProcess: linuxByProcess);

    return _result;
  }

  // Future<void> openFile() async {
  //   var filePath = r'/storage/emulated/0/update.apk';
  //   FilePickerResult? result = await FilePicker.platform.pickFiles();
  //
  //   if (result != null) {
  //     filePath = result.files.single.path!;
  //   } else {
  //     // User canceled the picker
  //   }
  //   final _result = await OpenFile.open(filePath);
  //   print(_result.message);
  //
  //
  // }
}
